package com.thoughtservice.jspdoc.processors;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.thoughtservice.jspdoc.JSPFileList;
import com.thoughtservice.jspdoc.JSPPage;
import com.thoughtservice.jspdoc.RE;
import com.thoughtservice.jspdoc.RESyntaxException;
import com.thoughtservice.jspdoc.utils.ProcessorUtils;

public class ProcessErrorPage implements DocProcessor{

	private final static Logger LOG = LoggerFactory.getLogger(ProcessErrorPage.class);

	public boolean process(JSPPage p, String pc, JSPFileList fileList)
			throws RESyntaxException {
		LOG.trace("Entering {}", "ProcessErrorPage");
		RE re;
		re = new RE("<%[:space:]*@[:space:]*page[:space:]*.*?errorPage=\"([:print:]*?)\"[:print:]*%>");
		re.match(pc);
		String epExpr = re.getParen(1);
		             
		if(epExpr != null) {
		   	// Find errorPage attribute value
		    String link = ProcessorUtils.figureLink(epExpr, p, JSPPage.ERRORPAGE);
		     if (link != null) {
				JSPPage dest = ProcessorUtils.getPage(link, fileList);
				if (dest != null)
					dest.addConnection(JSPPage.LINKSFROM, p.getName());
				}
		}
		LOG.trace("Exiting {}", "ProcessErrorPage");
	
		return false;
	}
}
